﻿using System;

namespace _04_CommandModel_Basic
{
    class Program
    {
        static void Main(string[] args)
        {
            Receiver receiver = new Receiver();
            Command cmd = new ConcreteCommand(receiver);
            Invoker invoker = new Invoker();
            invoker.SetCommand(cmd);
            invoker.ExecuteCommand();
            Console.Read();
        }
    }
    abstract class Command
    {
        protected Receiver receiver;
        public Command(Receiver receiver)
        {
            this.receiver = receiver;
        }
        abstract public void Execute();
    }
    class ConcreteCommand : Command
    {
        public ConcreteCommand(Receiver receiver) : base(receiver) { }
        public override void Execute()
        {
            receiver.Action();
        }
    }

    class Invoker
    {
        private Command cmd;
        public void SetCommand(Command cmd)
        {
            this.cmd = cmd;
        }
        public void ExecuteCommand()
        {
            cmd.Execute();
        }
    }
    internal class Receiver
    {
        public void Action()
        {
            Console.WriteLine("执行请求！");
        }
    }
}
